package  com.syqc.sensor.weight

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.syqc.custom.LeftRightTextView
import com.syqc.entity.OilDay
import com.syqc.monitor.R
import com.syqc.utils.Units

class WeightInfoAdapter :
    BaseQuickAdapter<OilDay, BaseViewHolder>(R.layout.item_sensor_weight_info) {
    var precision: String = "2"
    var unit: String = ""
    private val unitTime by lazy { context.getString(R.string.unit_num) }

    init {
        addChildClickViewIds(R.id.ivDayInfo, R.id.lrvWeightAdd, R.id.lrvWeightDown)
    }

    override fun convert(holder: BaseViewHolder, item: OilDay) {
        val position = holder.layoutPosition + 1
        val num = if (position < 10) "0$position" else "$position"
        holder.setText(R.id.tvItemNum, num)

        val mileStr = if (item.mile > 1000) {
            "${item.mileKm} ${Units.km}"
        } else {
            "${item.mile} ${Units.m}"
        }
        holder.run {
            getView<LeftRightTextView>(R.id.lrvWeightDate).setRightText(item.day)
            val lrvWeightAdd = getView<LeftRightTextView>(R.id.lrvWeightAdd)
            val lrvWeightDown = getView<LeftRightTextView>(R.id.lrvWeightDown)
            lrvWeightAdd.nextVisible(item.upTimes > 0)
            lrvWeightAdd.setRightText("${item.upTimes}$unitTime  ${item.upTotal} $unit")
            lrvWeightDown.nextVisible(item.downTimes > 0)
            lrvWeightDown.setRightText("${item.downTimes}$unitTime  ${item.downTotal} $unit")
            getView<LeftRightTextView>(R.id.lrvWeightMile).setRightText(mileStr)
        }
    }
}